from pathlib import Path
import random
from string import ascii_lowercase
import shutil
#import os

work_dir = Path('E:/pythonstudy/magedu/project/temp')
sub_dir = Path('a/b/c/d')
(work_dir / sub_dir).mkdir(parents=True)

sub_dirs = list(sub_dir.parents)[:-1] + [sub_dir]
filenames = (''.join(random.choices(ascii_lowercase,k=4)) for i in range(50))

for filename in filenames:
    (work_dir / random.choice(sub_dirs) / filename).touch()

src_dir = work_dir / 'a'
dst_dir = work_dir / 'dst'
# names = os.listdir(src_dir)
# print(names)
def ignore(src,names,ret=None,chars={'x','y','z'}):
    if ret is None:
        # return { name for name in names if name[0] not in chars and Path(src,name).is_file()}
        return set(filter(lambda name:name[0] not in chars and Path(src,name).is_file(),names))
# print(ignore(src,names))
shutil.copytree(src_dir,dst_dir,ignore=ignore)


# 做得不错
